package com.ehe.common.core.config;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.ehe.common.core.handler.TokenSuccessAfterHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
@EnableConfigurationProperties(CoreProperties.class)
public class CoreConfig {

    /** 项目配置文件 */
    @Autowired
    private CoreProperties coreProperties;

    /** 解析 token 成功后处理工具 */
    @Autowired(required = false)
    private TokenSuccessAfterHandler tokenSuccessAfterHandler;

    /**
     * 创建 rest 请求模板
     * @return rest 请求模板
     */
    @Bean
    @ConditionalOnMissingBean
    @SentinelRestTemplate
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }
}
